class Solution {
public:
    int dx[2] = { 0, 1 };
    int dy[2] = { 1, 0 };
    int m, n, cnt, ret = 0;
    bool vis[101][101];

    int wardrobeFinishing(int _m, int _n, int _cnt) {
        m = _m, n = _n, cnt = _cnt;
        dfs(0, 0);
        return ret;
    }

    int Digit(int num)
    {
        int sum = 0;
        while (num)
        {
            sum += (num % 10);
            num /= 10;
        }
        return sum;
    }

    void dfs(int i, int j)
    {
        ret++;
        vis[i][j] = true;

        for (int k = 0; k < 2; k++)
        {
            int x = i + dx[k], y = j + dy[k];
            if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && Digit(x) + Digit(y) <= cnt)
            {
                dfs(x, y);
            }
        }
    }
};